<template>
  <div class="p-16px">
    <el-card>
      <el-space wrap :size="16">
        <div class="flex items-center whitespace-nowrap">
          申请人：
          <el-input
            placeholder="请输入内容"
            v-model="params.receiver"
            clearable
          ></el-input>
        </div>
        <div class="flex items-center whitespace-nowrap">
          审核状态：
          <el-select
            v-model="params.status"
            placeholder="请选择"
            clearable
            style="width: 200px"
          >
            <el-option label="待审核" value="0"></el-option>
            <el-option label="已审核" value="1"></el-option>
            <el-option label="已驳回" value="2"></el-option>
          </el-select>
        </div>
        <div class="flex items-center whitespace-nowrap">
          提现时间：
          <el-date-picker
            v-model="params.time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </div>
        <el-button type="primary" @click="handleSearch">搜索</el-button>
      </el-space>
    </el-card>
    <el-card class="mt-16px">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="index" label="序号" width="80" />
        <el-table-column prop="receiver" label="申请人" min-width="180" />
        <el-table-column prop="applyTime" label="申请时间" min-width="180" />
        <el-table-column prop="applyAmount" label="申请金额" min-width="180" />
        <el-table-column prop="status" label="审核状态" min-width="180" />
        <el-table-column prop="remark" label="备注" min-width="180" />
        <el-table-column prop="approveName" label="审批人" min-width="180" />
        <el-table-column label="操作" min-width="180">
          <template #default="scope">
            <el-button type="primary" @click="handleAudit(scope.row)">
              审核
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="mt-16px flex justify-end">
        <el-pagination
          v-model:current-page="params.current"
          v-model:page-size="params.size"
          layout="prev, pager, next"
          background
          :total="total"
          @current-change="fetchList"
        />
      </div>
    </el-card>
    <el-dialog title="提现审核" v-model="showAuditDialog" style="width: 600px">
      <el-form :model="form" label-width="120px">
        <el-form-item label="审批意见">
          <el-input
            v-model="form.remark"
            placeholder="请输入"
            type="textarea"
            rows="4"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="success" @click="handleAuditSubmit(1)">
            通过
          </el-button>
          <el-button type="danger" @click="handleAuditSubmit(2)">
            驳回
          </el-button>
          <el-button @click="showAuditDialog = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref } from "vue";
const params = ref({
  receiver: "",
  time: [],
  status: "",
  size: 10,
  current: 1,
});
const showAuditDialog = ref(false);
const form = ref({
  remark: "",
});
const tableData = ref([
  {
    receiver: "张三",
    applyTime: "2024-01-01 10:00:00",
    applyAmount: "100",
    status: "成功",
    remark: "备注",
    approveName: "张三",
  },
]);
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);
const handleSearch = () => {
  console.log(params.value);
};
const handleAudit = (row) => {
  showAuditDialog.value = true;
  form.value = {
    remark: "",
    id: row.id,
  };
};
const handleAuditSubmit = (status) => {
  console.log(form.value);
  if (status === 2 && !form.value.remark) {
    ElMessage.warning("请输入审批意见");
    return;
  }
  showAuditDialog.value = false;
};
const fetchList = () => {
  console.log(params.value);
};
</script>

<style lang="scss" scoped></style>
